package com.gxwy.admin.dao;


import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.gxwy.admin.form.Admin;
@Repository
public class AdminDaoImpl implements AdminDao{
	
	@Autowired
	private SessionFactory sessionFactory;
//	没用
	@SuppressWarnings("unused")
// 处理事物的注解
	@Transactional
	
//  查询密码
	public int select(Admin admin) {
	    String hql="select count(*) from Admin u where u.user=:customername and password=:pass";
//      写好hql查询方法
	     Query query=sessionFactory.getCurrentSession().createSQLQuery(hql);
//        传递两个参数
		query.setParameter("customername",admin.getUser(),Hibernate.STRING);
		query.setParameter("pass",admin.getPassword(),Hibernate.STRING);
//		返回是否值
		List<?> list=query.list();
	     System.out.println(list.get(0));
//	     判断是否有值
	     for(int i=0;i<list.size();i++){
//              循环出值
	    	 int a=Integer.valueOf(list.get(i).toString());
           
	    	 System.out.println(a);
//          有值返回1
	    	 return a;
          }
//	     否则是0
	     	return 0;
    		   }
	@Transactional
	@SuppressWarnings("unused")
	public int selectId(String a) {
		// TODO Auto-generated method stub
	    String hql="select count(*) from Admin u where u.user=:customername";
	     Query query=sessionFactory.getCurrentSession().createSQLQuery(hql);
	     query.setParameter("customername",a,Hibernate.STRING);
	     List<?> list=query.list();
	     for(int i=0;i<list.size();i++){
	    	 int c=Integer.valueOf(list.get(i).toString());
	    	 return c;
	     }
		return 0;
	}
	     }
	
	

		
	
	


